<template>
    <div class="mui-numbox" data-numbox-min='1'>
		<button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
		<input id="test" class="mui-input-numbox" type="number" value="1" 
        @change="countChanged"/>
		<button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
	</div>

</template>
<script>
import mui from "../../lib/mui/js/mui.js";
export default {
  mounted() {
    mui(".mui-numbox").numbox();
    // console.log(this.max);
  },
  methods: {
    countChanged() {
      //每当文本框的值改变，把最新数据传给父组件
      // console.log(this.$refs.numbox.value);
      this.$emit("getcount", parseInt(this.$refs.numbox.value));
    }
  },
  props: ["max"],
  watch: {//动态监听max最后一次父组件传的值
    max: function(newVal, oldVal) {
        // 使用js api 设置numbox 最大值
      mui(".mui-numbox").numbox().setOption("max", newVal);
    }
  }
};
</script>
<style lang="scss" scoped>
</style>

